const express = require('express')
const multer  = require('multer');
// 创建路由实例
const userRouters = express.Router();
const listRouters = express.Router();
const adminRouters = express.Router();
const upRouters    = express.Router();
const storeRouters    = express.Router();
// M站 - 用户

const {loginIn,registerIn,loginOut} = require('./user/login')
const {userSearch,userEdit} = require('./user/user')

const {uploadAvatar} = require('./user/upload')
// 登录
userRouters.post('/login',loginIn)
// 注册
userRouters.post('/register',registerIn)
// 退出
userRouters.get('/loginout',loginOut)
// 用户信息获取
userRouters.post('/search',userSearch)
// 用户信息编辑
userRouters.post('/edit',userEdit)

// 用户头像上传
userRouters.post('/upload', multer({dest:'./public/avatar'}).any(),uploadAvatar)



// 带中间件拦截的接口(返回用户是否登录)
const {isLoginIn} = require('./list/isLoginIn')
listRouters.get('/loginin',isLoginIn)

//M站 - 健康信息&店铺查询&预约购买
const {getHealthlist,getHealthDetail,setHealthlist} = require('./list/health')

// 健康信息列表
listRouters.post('/health',getHealthlist)
// 健康信息详情
listRouters.post('/detail',getHealthDetail)
// 健康信息提交
listRouters.post('/add',setHealthlist)



// 我的记录 - 预约订单列表
const {getBuylist,addBuyList,cancelBuyList}   = require('./list/buy')
listRouters.post('/buy',getBuylist)
listRouters.post('/orderadd',addBuyList)
listRouters.post('/ordercancel',cancelBuyList)


// 店铺列表
const {getShopList}  = require('./list/shop')
listRouters.post('/shop',getShopList)










//后台管理
const {adminLoginIn,adminLoginOut,getAdminList,addAdminList,editAdminList} = require('./admin');

adminRouters.post('/login',adminLoginIn)
adminRouters.get('/loginout',adminLoginOut)


// 工作台数据
const {getWorkData} = require('./up/workdata')
upRouters.get('/workdata',getWorkData)

// 用户列表获取 设置黑名单 搜索姓名
const {getUserList,setUserStatus,searchName} = require('./up/userlist')

upRouters.get('/userlist',getUserList)
upRouters.post('/useredit',setUserStatus)
upRouters.post('/usersearch',searchName)
// 管理员列表接口
upRouters.get('/adminlist',getAdminList)
// 管理员添加接口
upRouters.post('/adminadd',addAdminList)
upRouters.post('/adminedit',editAdminList)

const {storeloginIn,storeloginOut} = require('./store/login')






const {getOrder,setOrderStatus,getStoreMessage} = require('./store/order')
const storeLogin = require('../middleware/storeLogin')
// 小程序商家平台 商家登录
storeRouters.post('/login',storeloginIn)
// 小程序商家平台 商家退出
storeRouters.get('/loginout',storeloginOut)

// 小程序商家平台 获取订单
storeRouters.post('/order',storeLogin,getOrder)
// 小程序商家平台 修改订单状态
storeRouters.post('/setstatus',storeLogin,setOrderStatus)
// 小程序商家平台 商家信息及数据统计
storeRouters.post('/getstoremessage',storeLogin,getStoreMessage)




// 导出路由
module.exports = {userRouters,listRouters,adminRouters,upRouters,storeRouters}